<!--
 * @Description: 表单
 * @Author: wang_k
 * @Date: 2023-05-16 14:35:02
 * @LastEditTime: 2023-05-18 15:23:04
 * @FilePath: /demo_important/src/views/Ceshi/components/archivesRighttable.vue
-->
<template>
  <div class="archives-table">
    <div class="archives-header">
      <el-upload
        :disabled="num === 0"
        class="upload-demo"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :before-remove="beforeRemove"
        multiple
        :limit="3"
        :on-exceed="handleExceed"
        :file-list="fileList"
      >
        <el-button
          size="small"
          type="primary"
        >点击上传/{{num}}</el-button>
        <div
          slot="tip"
          class="el-upload__tip"
        >只能上传jpg/png文件，且不超过500kb</div>
      </el-upload>
      <el-button
        type="primary"
        @click="handleUpload"
      >上传</el-button>
    </div>
    <el-table
      :data="tableData"
      border
      max-height="430"
      style="width: 100%"
    >
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="100"
      >
      </el-table-column>
      <el-table-column
        prop="name"
        label="文件名称"
        align="center"
        width="180"
      >
      </el-table-column>
      <el-table-column
        prop="url"
        label="上传时间"
        align="center"
      >
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
        width="180"
      >
        <template slot-scope="scope">
          <el-button
            style="margin-right: 10px"
            @click="handleEdit(scope.row)"
            type="text"
          >预览</el-button>
          <el-popconfirm
            @confirm="handleRemove(scope.row)"
            title="确定删除该图层吗？"
          >
            <el-button
              slot="reference"
              type="text"
            >删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <!-- 新增/编辑 -->
    <el-dialog
      width="50%"
      :title="titleName"
      :visible.sync="addShow"
      append-to-body
      :destroy-on-close="true"
    >
      <div class="form-content">
        <el-form
          ref="form"
          :model="editForm"
          label-width="80px"
        >
          <el-form-item label="图层名称">
            <el-input v-model="editForm.name"></el-input>
          </el-form-item>
          <el-form-item label="服务地址">
            <el-input v-model="editForm.url"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              @click="onSubmit"
            >确定</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios';
// import mapApi from "../baseMapApi";
export default {
  name: "baseMapTable",
  components: {},
  props: {},
  data() {
    return {
      addShow: false,
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      titleName: "",
      editForm: {
        name: "",
        url: "",
        lable: "1",
        type: "1",
      },
    };
  },
  computed: {
    num() {
      return 0
    },
    /* 目录树当前节点下数据 */
    treeNode() {
      return this.$store.getters["archives/treeNode"];
    },
    /* 新增父级节点id */
    treeParentId() {
      return this.$store.getters["archives/treeParentId"];
    },
  },
  watch: {
    treeNode: {
      handler(news, olds) {
        this.tableData = this.treeNode;
      },
      // immediate: true,
      deep: true,
    },
  },
  created() { },
  mounted() { },
  methods: {
    /* 上传 */
    handleUpload(data) {
      axios.get("/Ip-dev/arcManage/queryByPage").then(res => {
        console.log(res);
      })
      this.titleName = "新增";
      this.addShow = true;
      this.editForm.parentId = this.treeParentId;
    },
    /* 预览 */
    handleEdit(row) {
    },
    /* 删除 */
    handleRemove(row) {
      const data = {
        id: row.id,
      };
      mapApi
        .removeBaseMap(data)
        .then((res) => {
          this.handleReset();
        })
        .catch((error) => { });
    },
    /* 确定事件 */
    onSubmit() {
    },
    handleReset() {
      this.addShow = false;
      this.editForm = {
        name: "",
        url: "",
        lable: "1",
        type: "1",
      };
      this.$store.dispatch("archives/changeEditType", true);
    },
  },
};
</script>

<style scoped>
.archives-table {
  width: 100%;
  margin-left: 10px;
}
.archives-header {
  display: flex;
  align-items: center;
  justify-content: end;
  height: 50px;
  width: 100%;
}
</style>
